package com.lzw.bluetoothpractice.Activitys;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.lzw.bluetoothpractice.Adapters.MyCollectionAdapter;
import com.lzw.bluetoothpractice.Adapters.MyFansListAdapter;
import com.lzw.bluetoothpractice.Models.Attention;
import com.lzw.bluetoothpractice.Models.Collect;
import com.lzw.bluetoothpractice.Models.Fans;
import com.lzw.bluetoothpractice.Models._User;
import com.lzw.bluetoothpractice.R;

import java.util.ArrayList;
import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.http.bean.Init;
import cn.bmob.v3.listener.FindListener;
import cn.bmob.v3.listener.SaveListener;

public class MyFansActivity extends BaseActivity {


    private MyFansListAdapter myFansListAdapter;

    RecyclerView rc_fans;

     List<String> userIdlist =new ArrayList<>();
     List<Fans> fansList =new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_fans);
        InitNavBar(true,"我的粉丝",false);
        InitView();
        InitData();
    }
//BmobUser.getCurrentUser(_User.class).getObjectId()
    public void  InitView(){
        rc_fans=fd(R.id.rc_my_fans);
    }
    public void InitData(){


        BmobQuery<Fans> query = new BmobQuery<>();
        query.addWhereEqualTo("UserId", BmobUser.getCurrentUser(_User.class).getObjectId());
        query.findObjects(new FindListener<Fans>() {
            @Override
            public void done(List<Fans> object, BmobException e) {
                if (e == null) {
                    //fansList=object;

                    BmobQuery<Attention> query1 = new BmobQuery<>();
                    query1.addWhereEqualTo("attedUserId", BmobUser.getCurrentUser(_User.class).getObjectId());
                    query1.findObjects(new FindListener<Attention>() {
                        @Override
                        public void done(List<Attention> list, BmobException e) {
                            if (e==null){
                                for (Attention s:
                                        list) {
                                    userIdlist.add(s.getAttUserId());

                                }
                                Log.e("fans",object.toString());
                                Log.e("userIdlist",userIdlist.toString());
                                rc_fans.setLayoutManager(new LinearLayoutManager(MyFansActivity.this));
                                //rchealthyList.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));
                                myFansListAdapter=new MyFansListAdapter(MyFansActivity.this,object,userIdlist);

                                rc_fans.setAdapter(myFansListAdapter);
                            }else {
                                Toast toast=Toast.makeText(MyFansActivity.this,"查询数据失败"+e.getMessage(),Toast.LENGTH_LONG);
                                Log.e("错误：",e.getMessage());
                                toast.show();
                            }


                        }
                    });
                    //Article article=new Article();

                } else {
                    Toast toast=Toast.makeText(MyFansActivity.this,"查询数据失败"+e.getMessage(),Toast.LENGTH_LONG);
                    Log.e("错误：",e.getMessage());
                    toast.show();
                }
            }
        });
    }
}
